<template>
  <div class="chart" ref="chart"></div>
</template>

<script>
export default {
  name: "Charts",
  props: {
    option: {
      type: Object,
      default: () => {
        return {};
      },
    },
  },
  data() {
    return {
      datas: [],
      myChart: null,
    };
  },
  watch: {
    option: {
      handler(newValue, oldValue) {
        this.init();
      },
      deep: true,
    },
  },
  mounted() {
    this.init();
  },
  computed: {
  },
  methods: {
    init() {
      //数据
      this.myChart = this.$echarts.init(this.$refs.chart);
      this.myChart.clear()
      this.myChart.setOption(this.option);
      this.myChart.resize();

      this.myChart.on("click", (data) => {
          return
        //根据一些信息添加一些响应函数
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.chart {
  width: 100%;
  height: 100%;
}
</style>